home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 July: Mac OS SDK / Dev.CD Jul 96 SDK / Dev.CD Jul 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / ODF / ODFLibrary / Sources / ODFLibrary.cpp next >
Encoding:
Text File  |  1996-04-25  |  4.1 KB  |  154 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                ODFLib.cpp
  4. //    Release Version:    $ ODF 1 $
  5. //
  6. //    Copyright:    (c) 1993-1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWOS.hpp"
  11.  
  12. #ifndef FWENVDEF_H
  13. #include "FWEnvDef.h"
  14. #endif
  15.  
  16. #ifdef FW_BUILD_MAC
  17.  
  18. #ifndef FWCFMRES_H
  19. #include "FWCFMRes.h"
  20. #endif
  21.  
  22. #include <CodeFragments.h>
  23. #include <Events.h>
  24. //z#include "SLExcept.h"
  25.  
  26. #endif
  27.  
  28. #if defined(SYMANTEC_CPLUS) && defined(FW_BUILD_MAC)
  29.     #define ODF_COLLEC_CFMINIT PartCFMInit
  30. #endif
  31.  
  32. //========================================================================================
  33. // Prototypes
  34. //========================================================================================
  35.  
  36. #ifdef FW_BUILD_MAC
  37. extern "C" pascal OSErr ODF_LIBRARY_CFMINIT (CFragInitBlockPtr initBlkPtr);
  38. extern "C" pascal void  ODF_LIBRARY_CFMTERM (void);
  39.  
  40. #if GENERATINGPOWERPC
  41.  
  42. #ifdef __MWERKS__
  43. #    if __MWERKS__ < 0x0800
  44. extern "C" void __sinit();
  45. extern "C" void    __destroy_global_chain(void);
  46. #    else
  47. extern "C" short __initialize();
  48. extern "C" void    __terminate(void);
  49. #    endif
  50. #elif defined __MRC__
  51. extern "C" __init_lib(CFragInitBlockPtr initBlkPtr);
  52. #endif
  53.  
  54. #endif // GENERATINGPOWERPC
  55.  
  56. #endif // FW_BUILD_MAC
  57.  
  58. //========================================================================================
  59. //    Global Variable
  60. //========================================================================================
  61. //    FW_gInstance is initialized in DLLMain for Windows
  62. //    FW_gInstance is defined in FWCFMRes.cpp for the Mac
  63. #ifdef FW_BUILD_WIN
  64. FW_Instance FW_gInstance = NULL;
  65. #endif
  66.  
  67. //========================================================================================
  68. // Initialization methods
  69. //========================================================================================
  70.  
  71. #ifdef FW_BUILD_WIN32
  72. //----------------------------------------------------------------------------------------
  73. // DllMain
  74. //----------------------------------------------------------------------------------------
  75. extern "C" BOOL WINAPI DllMain(HINSTANCE    hDLL,
  76.                                 DWORD        dwReason,
  77.                                 LPVOID        /* lpReserved */)
  78. {
  79.     if(dwReason == DLL_PROCESS_ATTACH)
  80.     {
  81.         // Save instance handle for future use
  82.         FW_gInstance = hDLL;
  83.     }
  84.  
  85.     return TRUE;
  86. }
  87. #endif
  88.  
  89. #ifdef FW_BUILD_MAC
  90. //----------------------------------------------------------------------------------------
  91. // ODF_LIBRARY_CFMINIT (Has to be upper case because of the 68K Linker)
  92. //----------------------------------------------------------------------------------------
  93.  
  94. extern "C" pascal OSErr ODF_LIBRARY_CFMINIT(CFragInitBlockPtr initBlkPtr)
  95. {
  96.  
  97. #ifdef FW_DEBUG
  98.     #define FW_COMMAND 0x37
  99.     
  100.     KeyMap theKeyMap;
  101.     ::GetKeys(theKeyMap);
  102.     const unsigned char *theKeys = (const unsigned char *) theKeyMap;
  103.     if ((theKeys[FW_COMMAND >> 3] >> (FW_COMMAND & 7)) & 1)
  104.         ::DebugStr("\p ODF_LIBRARY_CFMINIT");
  105. #endif
  106.  
  107.     // Shared libraries don't get there static objects initialized correctly without
  108.     // calling __initialize or __CPlusInit for MetroWerks or MrC respectively.
  109.  
  110. #ifdef __MWERKS__
  111.     #if __MWERKS__ < 0x0800
  112.         __sinit();
  113.     #else
  114.         __initialize();
  115.     #endif
  116. #elif defined __MRC__
  117.     __init_lib(initBlkPtr);
  118. #endif
  119.  
  120. #ifndef FW_NATIVE_EXCEPTIONS
  121.     // FW_gInStaticInit is initialized to a special magic number before static initialization (at linktime)
  122.     // within SLExcept.cpp.  Here we clear it to zero.  This allows FWExcLib to
  123.     // understand when static objects are being constructed.
  124.     extern long FW_gInStaticInit;
  125.     FW_gInStaticInit = 0L;
  126. #endif
  127.     
  128.     return FW_CAcquireCFMResourceAccess::PrivInitLibraryResources(initBlkPtr);
  129. }
  130. #endif
  131.  
  132. #ifdef FW_BUILD_MAC
  133. //----------------------------------------------------------------------------------------
  134. // ODFCFMTERM
  135. //----------------------------------------------------------------------------------------
  136.  
  137. extern "C" pascal void ODF_LIBRARY_CFMTERM(void)
  138. {
  139.     FW_CAcquireCFMResourceAccess::PrivCloseLibraryResources();
  140.     
  141. #if GENERATINGPOWERPC
  142. #    ifdef __MWERKS__
  143. #        if __MWERKS__ < 0x0800
  144.     __destroy_global_chain();
  145. #        else
  146.     __terminate();
  147. #        endif
  148. #    endif
  149. #endif
  150. }
  151.  
  152. #endif
  153.  
  154.